var mongoose=require('mongoose');
var Post=mongoose.model('Post',{
    title:String,
    authors:[String],
    comment:{
        good:Number,
        general:Number,
        comments:[
            {
                content:String,
                like:Number
            }
        ]
    }

});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');

var title='post12-2';
Post.update({title:title},{
    comment:{
        good:95,
        general:3,
        comments:[
            {
                content:'c1',
                like:0
            },
            {
                content:'c2',
                like:0
            }
        ]
    }
},{upsert:true},(err,r)=>{
    console.log('Update:',err,r);

    Post.update({title:title},{
        $inc:{
            'comment.comments.0.like':100,
            'comment.comments.1.like':200
        }
    },(e,r)=>{
        console.log('定位操作1：',e,r);

        Post.find({title:title},(e,r)=>{
            console.log('Find:\n',e);
            console.log(JSON.stringify(r,null,2));
            process.exit(1);
        });
    });

});


/*
 * .点号数组定位操作，访问数组点号指定的下标元素
 *
 * 点号之前的字段可以是多级嵌套的(如 comment.comments.0.like)
 * */





